using UnityEngine;
using UnityEngine.UI;

namespace PKGames
{
	[RequireComponent(typeof(Image))]
	public class ImageView : ObjectView
	{
		private Image _image;

		private Animation _animation;

		private const string _popupAnimation = "PopUpAnimation";

		private const string _pressAnimation = "PressAnimation";

		private const string _releaseAnimation = "ReleaseAnimation";

		private void Awake()
		{
			base.gameObject.RemoveCloneFromName();
			_animation = GetComponent<Animation>();
			_image = GetComponent<Image>();
			Init(_image.sprite);
		}

		private void Init(Sprite sprite)
		{
			_image.sprite = sprite;
		}

		public Vector2 GetSize()
		{
			return _image.rectTransform.rect.size;
		}

		public void OnPress()
		{
			if (_animation != null)
			{
				_animation.Play("PressAnimation");
			}
		}

		public void OnRelease()
		{
			if (_animation != null)
			{
				_animation.Play("ReleaseAnimation");
			}
		}

		public void OnAppear()
		{
			if (_animation != null)
			{
				_animation.Play("PopUpAnimation");
			}
		}

		public void StopAnimations()
		{
			if (_animation != null)
			{
				_animation.Stop();
			}
		}
	}
}
